using System;
using System.Collections.Generic;
using SCG.SolarVengeanceEngine;
using System.Windows;
using SCG.SolarVengeance.Brains;
using SCG.General;

namespace SCG.SolarVengeance.Scenarios
{
    public class Tutorial : Scenario
    {
        private BlackHole wanderer;
        private ScenarioParameter _TutorialLevel;
        private StarSystem MyCap;
        private StarSystem ECap;
        private StarSystem TmpStar;
        private Dictionary<string, double> StarX = new Dictionary<string, double>();
        private Dictionary<string, double> StarY = new Dictionary<string, double>();
        private int tutstep = 0;
        private int dproc = 0;
        private int warshipwpn = 0;

        public Tutorial()
        {
            _TutorialLevel = CreateParameter("Tutorial Chapter", 1, 1, 4);
        }

        public override PlayModeRecommendation Recommendation
        {
            get
            {
                return PlayModeRecommendation.Solo;
            }
        }

        public override string Author
        {
            get{ return "Beat2k"; }
        }
        public override string Description
        {
            get { 
                return "This scenario will teach you the basics of the game. Make sure you use Beginner as the brain."+
                       "Also, this Tutorial has 4 parts. To access each part of the tutorial, Use the Scenaro Parameter to the left of the menu."; 
            }
        }
        public override int MaxPlayers
        {
            get
            {
                return 2;
            }
        }
        public override int DefaultCapitalResources
        {
            get
            {
                return 100;
            }
        }

        //Display a new message
        private string _msg = "";
        private void DisplayMessage(string msg)
        {
            _msg = msg;
        }

        //custom rendering
        public override void CustomRendering(ISVCustomRenderer renderer)
        {
            renderer.DrawWrappedText(_msg, SCGColor.Yellow, 12);
        }

        public override void ProcessImpulse(int impulse)
        {
            if (_TutorialLevel.Value == 1)
            {
                if (impulse == 2)
                {
                    tutstep = 0;
                    DisplayMessage("Welcome to the Tutorial Part 1.");
                }
                else if (impulse == 4)
                {
                    DisplayMessage("You can pause the Tutorial at any time by clicking the \"Pause\" button above.  We've now paused the game.  Take a moment to scroll around the mini-map to the lower right of the screen to learn how to navigate.  Click the VCR-Style \"Play\" button above to resume the action when ready.");
                }
                else if (impulse == 5)
                {
                    if (Game.Host != null)
                        Game.Host.Pause();
                }
                else if (impulse == 13)
                {
                    DisplayMessage("Here you will learn how to build from your Capital StarSystem, and how to take over other StarSystems.");
                }
                else if (impulse == 18)
                {
                    DisplayMessage("Your first task is to build a WarShip.");
                    dproc = 0;
                    tutstep++;
                }
                else if (impulse == 23 && tutstep == 1)
                {
                    DisplayMessage("To build a WarShip, click on the blue \"StarShip\" button at the lower right of the window.");
                }
                else if (impulse == 28 && tutstep == 1)
                {
                    DisplayMessage("You then see the Build StarShip interface, including a list of available StarShips.  On the StarShip list, select WarShip.");
                }
                else if (impulse == 33 && tutstep == 1)
                {
                    DisplayMessage("Next, click one of the 8 directional arrows to build the WarShip in that position relative to your Capital StarSystem.");
                }

                if (tutstep == 1)
                {
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.ShipType == StarShipType.WarShip)
                                tutstep = 2;
                        }
                    }
                }
                else if (tutstep == 2)
                {
                    dproc++;
                    if (dproc == 2)
                    {
                        DisplayMessage("Alright, now click on your WarShip.");
                    }
                    else if (dproc == 7)
                    {
                        DisplayMessage("When you click on your WarShip, the cursor on the map changes from an arrow to a target symbol.");
                    }
                    else if (dproc == 12)
                    {
                        DisplayMessage("To move your selected WarShip, click on any space on the map.");
                        tutstep++;
                        dproc = 0;
                    }
                }
                else if (tutstep == 3)
                {
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.Order != null)
                                if (ship.Order.OrderType == OrderType.Move)
                                    tutstep = 4;
                        }
                    }
                }
                else if (tutstep == 4)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Good, now watch as your WarShip moves towards the destination.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("When your WarShip completes an order, it will wait for another order.");
                    }

                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.Order == null)
                            {
                                tutstep = 5;
                                dproc = 0;
                            }
                        }
                    }
                }
                else if (tutstep == 5)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Let's give it another order.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("This time, you will order your WarShip to target a StarSystem.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("Click on your WarShip.");
                        TmpStar = DynamicEvents.CreateStarSystem(40, 45, 10, 8, 0, 0);
                    }
                    else if (dproc == 16)
                    {
                        DisplayMessage("After your WarShip is selected again, you will order it to target the StarSystem " + TmpStar.Name + ".");
                    }
                    else if (dproc == 21)
                    {
                        DisplayMessage("To target a StarSystem, simply click on the StarSystem you want to target.");
                    }

                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.Order != null)
                                if (ship.Order.OrderType == OrderType.TargetStarSystem)
                                {
                                    dproc = 0;
                                    tutstep = 6;
                                }
                        }
                    }
                }
                else if (tutstep == 6)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Good, now watch as your WarShip moves towards the StarSystem.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Your WarShip is destroyed in the process of attacking a StarSystem.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("But the StarSystem's Shields are reduced by the Weapon rating of the WarShip.");
                    }
                    else if (dproc == 16)
                    {
                        DisplayMessage("If your WarShip's Weapon rating is greater than the StarSystem's Shields, you conquer the StarSystem!");
                    }
                    else if (dproc == 26)
                    {
                        DisplayMessage("Now build another WarShip, this time with a Weapons rating large enough to conquer the StarSystem.");
                    }
                    else if (dproc == 33)
                    {
                        DisplayMessage("Remember, to conquer the StarSystem, you need a WarShip with a Weapons rating greater than the StarSystem's Shields.");
                    }
                    else if (dproc == 40)
                    {
                        DisplayMessage("To see how many Shields a StarSystem has, just click on the StarSystem.");
                    }
                    else if (dproc == 45)
                    {
                        DisplayMessage("Here you can tell who owns the StarSystem, and other useful info.");
                    }
                    else if (dproc == 50)
                    {
                        DisplayMessage("Click back on your Capital, then click the \"StarShip\" button again.");
                    }
                    else if (dproc == 55)
                    {
                        DisplayMessage("This time, change the Weapons rating of the WarShip to one greater than the Shields of the StarSystem.  Then click one of the arrows to build the WarShip.");
                        tutstep = 7;
                    }
                }
                else if (tutstep == 7)
                {
                    warshipwpn = 0;
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.ShipType == StarShipType.WarShip)
                            {
                                warshipwpn = warshipwpn = ship.Value;
                                if (warshipwpn > TmpStar.Shields)
                                {
                                    tutstep = 8;
                                    dproc = 0;
                                }
                            }
                        }
                    }
                }
                else if (tutstep == 8)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Good, now order your WarShip to target the StarSystem.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Click on your WarShip and the Target icon will appear, then click on the StarSystem to target it.");
                    }
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.Order != null)
                                if (ship.Order.OrderType == OrderType.TargetStarSystem)
                                {
                                    dproc = 0;
                                    tutstep = 9;
                                }
                        }
                    }
                }
                else if (tutstep == 9)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Good, now your WarShip is targeting the StarSystem.");
                    }
                    if (TmpStar.Owner == Game.Players[0])
                    {
                        dproc = 0;
                        tutstep = 10;
                    }
                }
                else if (tutstep == 10)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Great, now you control the StarSystem you have conquered!");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Now you can build WarShips from your new StarSystem just like you did from your Capital.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("Now you are going to target another StarSystem.");
                    }
                    else if (dproc == 16)
                    {
                        TmpStar = DynamicEvents.CreateStarSystem(45, 40, 20, 45, 20, 50);
                        DisplayMessage("StarSystem " + TmpStar.Name + " has many Shields. (45 Shields if you click it to see.)");
                    }
                    else if (dproc == 21)
                    {
                        DisplayMessage("To build one WarShip to conquer this StarSystem would be too expensive for the Resources you currently have ...");
                    }
                    else if (dproc == 26)
                    {
                        DisplayMessage("... but there is another way!");
                    }
                    else if (dproc == 31)
                    {
                        DisplayMessage("Instead of one WarShip with a high Weapons rating, you can build many WarShips with lower Weapons rating for fewer Resources.");
                    }
                    else if (dproc == 38)
                    {
                        DisplayMessage("Click on your Capital StarSystem and build several WarShips from it.");
                    }
                    else if (dproc == 45)
                    {
                        DisplayMessage("You will need many WarShips to conquer this StarSystem.");
                        tutstep = 11;
                        dproc = 0;
                    }
                }
                else if (tutstep == 11)
                {
                    dproc++;
                    if (dproc == 9)
                    {
                        DisplayMessage("Hint, move your WarShips away from the Capital StarSystem to build more.");
                    }
                    warshipwpn = 0;
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.ShipType == StarShipType.WarShip)
                            {
                                warshipwpn = warshipwpn + ship.Value;
                                if (warshipwpn > TmpStar.Shields)
                                {
                                    tutstep = 12;
                                    dproc = 0;
                                }
                            }
                        }
                    }
                }
                else if (tutstep == 12)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("OK, before attacking the StarSystem, there is a feature that will allow you to order multiple StarShips at once.");
                    }
                    else if (dproc == 9)
                    {
                        DisplayMessage("Click on a space to the top left of your fleet of WarShips and hold down the mouse button to form a selection rectangle.");
                    }
                    else if (dproc == 14)
                    {
                        DisplayMessage("Drag the rectangle over all the WarShips that you built.");
                    }
                    else if (dproc == 19)
                    {
                        DisplayMessage("Now release the mouse button.");
                    }
                    else if (dproc == 24)
                    {
                        DisplayMessage("You should see squares surrounding all of the WarShips you selected.");
                    }
                    else if (dproc == 29)
                    {
                        DisplayMessage("Order your fleet of WarShips to target the StarSystem!");
                    }
                    else if (dproc == 35)
                    {
                        DisplayMessage("This multi-select feature will allow you to coordinate multiple StarShips at once, including WarShips.");
                    }
                    if (TmpStar.Owner == Game.Players[0])
                    {
                        dproc = 0;
                        tutstep = 13;
                    }
                }
                else if (tutstep == 13)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Alright! Now you are learning!");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("See how you can conquer an almost impregnible StarSystem using only the Resources from your Capital?");
                    }
                    else if (dproc == 13)
                    {
                        DisplayMessage("Now you are ready to conquer a Star Cluster.");
                    }
                    else if (dproc == 16)
                    {
                        for (int d = 0; d < 8; d++)
                        {
                            int value = Random(1, 20);
                            if (value == 1)
                                value = Random(1, 20);
                            int shields = Random(0, value - 1);
                            int scanners = (int)(Random(0, value) * Random(0, 2));
                            if (scanners == 1)
                                scanners = 0;
                            double resources = Random(0, value) * Random(0, 3);
                            StarSystem system = DynamicEvents.CreateStarSystem(Random(30, 50), Random(30, 50), value, shields, scanners, resources);
                        }
                    }
                    warshipwpn = 0;
                    if (dproc >= 17)
                    {
                        if (dproc == 20)
                        {
                            DisplayMessage("There is another feature that can help you build WarShips.");
                        }
                        else if (dproc == 25)
                        {
                            DisplayMessage("This feature is called Auto-Build.");
                        }
                        else if (dproc == 30)
                        {
                            DisplayMessage("Click on your Capital.");
                        }
                        else if (dproc == 35)
                        {
                            DisplayMessage("Notice the red \"Auto\" buttons to the right of each of the Build buttons.");
                        }
                        else if (dproc == 40)
                        {
                            DisplayMessage("Those \"Auto\" buttons allow you to Auto-Build Shields, Scanners, and StarShips.");
                        }
                        else if (dproc == 45)
                        {
                            DisplayMessage("Also, there is a blue link labeled \"Warship E8 W4\".");
                        }
                        else if (dproc == 50)
                        {
                            DisplayMessage("If you click this link, you can select what you want this StarSystem to Auto-Build.");
                        }
                        else if (dproc == 60)
                        {
                            DisplayMessage("When you are done, click on the green \"Accept\" button to start Auto-Building that StarShip, or click Cancel to exit Auto-Build.");
                        }
                        else if (dproc == 70)
                        {
                            DisplayMessage("Clicking the red \"Auto\" button next to the Build StarShip button will switch Auto-Build on or off.");
                        }
                        else if (dproc == 75)
                        {
                            DisplayMessage("Now, try to conquer the entire Star Cluster!");
                        }
                        foreach (StarSystem star in Game.StarSystems)
                        {
                            if (star.Owner == Game.Players[0])
                                warshipwpn++;
                            if (warshipwpn >= Game.StarSystems.Count - 1)
                            {
                                tutstep = 14;
                                dproc = 0;
                            }
                        }
                    }
                }
                else if (tutstep == 14)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("OK, now you are ready to take on the final test.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Now you are ready to take on the enemy!");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("You final test is to take over the enemy Capital to win the game.");
                    }
                    else if (dproc == 16)
                    {
                        DisplayMessage("You are about to face the opponent for the first time!");
                    }
                    else if (dproc == 21)
                    {
                        DisplayMessage("Go get the opponent!");
                        for (int wh = Game.Wormholes.Count - 1; wh >= 0; wh--)
                        {
                            DynamicEvents.RemoveObject(Game.Wormholes[wh]);
                        }

                        for (int d = 0; d < 4; d++)
                        {
                            int value = Random(1, 20);
                            if (value == 1)
                                value = Random(1, 20);
                            int shields = 0;
                            int scanners = (int)(Random(0, value) * Random(0, 2));
                            if (scanners == 1)
                                scanners = 0;
                            double resources = Random(0, value) * Random(0, 3);
                            StarSystem system = DynamicEvents.CreateStarSystem(Random(50, 70), Random(50, 70), value, shields, scanners, resources);
                            system.Owner = Game.Players[1];
                        }
                    }
                }
                //else if (dproc == 43)
                //{
                //    DisplayMessage("You will occasionally find a StarSystem with a StarShip bonus.");
                //}
                //else if (dproc == 48)
                //{
                //    DisplayMessage("If you conquered a StarSystem with a StarShip bonus, you now have the ability to build that starship from any StarSystem.");
                //}
            }
            else if (_TutorialLevel.Value == 2)
            {
                StarShip enemyship = null;
                if (impulse == 1)
                {
                    enemyship = DynamicEvents.CreateStarShip(58, 61, Game.Players[1], StarShipType.WarShip, 20, 1, false);
                    tutstep = 0;
                    dproc = 0;
                    DisplayMessage("Welcome to the Tutorial Part 2.");
                }
                else if (impulse == 10)
                {
                    DisplayMessage("Here you will learn how to battle against enemy StarShips, and how to use some of the other StarShip types in the game.");
                }
                else if (impulse == 15)
                {
                    DisplayMessage("The first thing you will learn before destroying enemy StarShips is the Defend order.");
                }
                else if (impulse == 20)
                {
                    DisplayMessage("Oh no! The enemy has arrived early, looks like we need to get going right away.");
                }
                if (enemyship == null)
                {
                    if (impulse == 27)
                    {
                        DisplayMessage("Whew, good thing that was not a big WarShip!");
                    }
                }
                if (impulse == 30)
                {
                    DisplayMessage("The enemy is definitely not playing playing around today!");
                }
                else if (impulse == 35)
                {
                    DisplayMessage("Let's get started right away before the enemy strikes again!");
                }
                else if (impulse == 40)
                {
                    DisplayMessage("Build a WarShip from your Capital.");
                }
                if (tutstep == 0)
                {
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.ShipType == StarShipType.WarShip)
                            {
                                tutstep = 1;
                                dproc = 0;
                            }
                        }
                    }
                }
                else if (tutstep == 1)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("OK, now when you click on the WarShip, DON'T click on the map.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Instead, look on the right panel and find the Defend order button.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("Click on the Defend button and click on any spot on the map. Including your Capital StarSystem.");
                    }
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.Order != null)
                                if ((ship.Order.OrderType == OrderType.DefendPoint) | (ship.Order.OrderType == OrderType.Defend))
                                {
                                    dproc = 0;
                                    tutstep = 2;
                                }
                        }
                    }
                }
                else if (tutstep == 2)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("See how there is a green line going from the WarShip to the point of the map?");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("A green line means the WarShip is in Defend mode.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("When a WarShip is in Defend mode, The WarShip will attack anything near the defended point.");
                    }
                    else if (dproc == 19)
                    {
                        DisplayMessage("Now let's see how it works.");
                        DynamicEvents.CreateStarShip(48, 48, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(49, 49, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(51, 51, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                    }
                    else if (dproc >= 21)
                    {
                        foreach (StarShip sh in Game.StarShips)
                        {
                            if (sh.Owner != Game.Players[0])
                                enemyship = sh;
                        }
                        if (enemyship == null && MyCap.Shields >= 9)
                        {
                            DisplayMessage("Good job! Defend worked very well.");
                        }
                        if (enemyship == null && MyCap.Shields < 9)
                        {
                            DisplayMessage("Looks like the enemy is getting tougher.");
                        }
                        if (enemyship == null)
                        {
                            tutstep = 3;
                            dproc = 0;
                        }
                    }
                }
                else if (tutstep == 3)
                {
                    dproc++;
                    if (dproc == 5)
                    {
                        DisplayMessage("Now let's build Drones this time to assist the WarShip.");
                    }
                    else if (dproc == 10)
                    {
                        DisplayMessage("A Drone is a StarShip that can destroy another StarShip in one shot.");
                    }
                    else if (dproc == 15)
                    {
                        DisplayMessage("You are going to use the Drones to Defend your Capital from attack.");
                    }
                    else if (dproc == 20)
                    {
                        DisplayMessage("Click on your Capital, and then the Build StarShip button.");
                    }
                    else if (dproc == 25)
                    {
                        DisplayMessage("Select the Drone from the list and build eight of them.");
                    }
                    warshipwpn = 0;
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.ShipType == StarShipType.Drone)
                            {
                                warshipwpn++;
                            }
                        }
                    }
                    if (warshipwpn >= 8)
                    {
                        tutstep = 4;
                        dproc = 0;
                    }
                }
                else if (tutstep == 4)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("OK, now order your Drones to defend your Capital. Use multi-select to do this faster.");
                    }
                    else if (dproc == 10)
                    {
                        DisplayMessage("Well now, what is the enemy up to now?");
                    }
                    else if (dproc == 15)
                    {
                        DynamicEvents.CreateStarShip(48, 48, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(48, 49, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(49, 48, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(50, 50, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(50, 49, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(49, 50, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(49, 49, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(48, 50, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(50, 48, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(51, 51, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DisplayMessage("Maybe the enemy gave up?");
                    }
                    else if (dproc == 26)
                    {
                        DisplayMessage("Ahh! I spoke too soon! There he is.");
                    }
                    else if (dproc == 30)
                    {
                        DisplayMessage("Get ready to build more Drones. The enemy is bigger this time.");
                    }
                    else if (dproc >= 31)
                    {
                        foreach (StarShip sh in Game.StarShips)
                        {
                            if (sh.Owner != Game.Players[0])
                                enemyship = sh;
                        }
                        if (enemyship == null)
                        {
                            tutstep = 5;
                            dproc = 0;
                        }
                    }
                }
                else if (tutstep == 5)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("This is getting harder isn't it?");
                    }
                    else if (dproc == 5)
                    {
                        DisplayMessage("Don't give up now, you are doing good at this.");
                    }
                    else if (dproc == 10)
                    {
                        DisplayMessage("OK, now it's time to learn how to Target enemy StarShips.");
                    }
                    else if (dproc == 15)
                    {
                        DisplayMessage("Build a Drone again from your Capital.");
                        DynamicEvents.CreateStarShip(48, 48, Game.Players[1], StarShipType.WarShip, 8, 8, false);
                    }
                    else if (dproc == 20)
                    {
                        DisplayMessage("To target a StarShip, just click on an enemy StarShip after clicking your StarShip.");
                    }
                    else if (dproc == 27)
                    {
                        DisplayMessage("Quickly now, there he is again!");
                    }
                    else if (dproc == 30)
                    {
                        DisplayMessage("Select your Drones and target that StarShip before it gets your Capital.");
                    }
                    else if (dproc >= 36)
                    {
                        foreach (StarShip sh in Game.StarShips)
                        {
                            if (sh.Owner != Game.Players[0])
                                enemyship = sh;
                        }
                        if (enemyship == null)
                        {
                            tutstep = 6;
                            dproc = 0;
                        }
                    }
                }
                else if (tutstep == 6)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        warshipwpn = 0;
                        foreach (StarShip sh in Game.StarShips)
                        {
                            if (sh.Owner == Game.Players[0])
                                if (sh.ShipType == StarShipType.WarShip)
                                    warshipwpn = sh.Health;
                        }
                        if (warshipwpn < 100)
                           DisplayMessage("Did you see that? The enemy WarShip damaged your WarShip.");
                    }
                    else if (dproc == 5)
                    {
                        DisplayMessage("The only way an enemy WarShip can damage your WarShip is if the enemy Warship has more Weapons than your WarShip.");
                    }
                    else if (dproc == 15)
                    {
                        DisplayMessage("Obviously the Drones stopped it, but if the enemy builds another WarShip that big ...");
                    }
                    else if (dproc == 20)
                    {
                        DisplayMessage("... you could be in trouble!");
                    }
                    else if (dproc == 25)
                    {
                        DisplayMessage("Fortunately, you have another StarShip that can destroy almost any StarShip instantly.");
                    }
                    else if (dproc == 30)
                    {
                        DisplayMessage("The E-Mine is a very slow in movement, but very quick effective in battle.");
                    }
                    else if (dproc == 35)
                    {
                        DisplayMessage("E-Mines can destroy an enemy StarShip the instant the StarShip moves adjacent to it.");
                    }
                    else if (dproc == 40)
                    {
                        DisplayMessage("Now let's build some E-Mines ...");
                        DynamicEvents.CreateStarShip(48, 48, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(48, 49, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(49, 48, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(50, 50, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(50, 49, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        DynamicEvents.CreateStarShip(49, 50, Game.Players[1], StarShipType.WarShip, 8, 1, false);
                    }
                    else if (dproc == 45)
                    {
                        DisplayMessage("Click on your Capital, and then the Build StarShip button.");
                    }
                    else if (dproc == 51)
                    {
                        DisplayMessage("Select the E-Mine and build... Oh, here he is again! Is he ever going to give up?");
                    }
                    else if (dproc >= 52)
                    {
                        foreach (StarShip sh in Game.StarShips)
                        {
                            if (sh.Owner != Game.Players[0])
                                enemyship = sh;
                        }
                        if (enemyship == null)
                        {
                            tutstep = 7;
                            dproc = 0;
                        }
                    }
                }
                else if (tutstep == 7)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("OK, the enemy is getting out of control now!");
                    }
                    else if (dproc == 5)
                    {
                        DisplayMessage("Time to see where he is coming from.");
                        for (int wh = Game.Wormholes.Count - 1; wh >= 0; wh--)
                        {
                            DynamicEvents.RemoveObject(Game.Wormholes[wh]);
                        }
                        ECap.Resources = 100;
                    }
                    else if (dproc == 10)
                    {
                        DisplayMessage("Build a SpyShip to see those StarShips before it is too late!");
                    }
                    else if (dproc == 15)
                    {
                        DisplayMessage("A SpyShip works like the scanners of a StarSystem.");
                    }
                    else if (dproc == 20)
                    {
                        DisplayMessage("However, the Spyship can identify StarShips within the SpyShip's scanner range, telling you what kind they are.");
                    }
                    else if (dproc == 25)
                    {
                        DisplayMessage("Keep an eye out for enemy StarShips. Don't spend too many Resources!");
                    }
                    else if (dproc >= 30)
                    {
                        if (Random(0, 100) >= 95)
                        {
                            DynamicEvents.CreateStarShip(Random(48, 52), Random(48, 52), Game.Players[1], StarShipType.WarShip, 8, 1, false);
                        }
                    }
                    warshipwpn = 0;
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.ShipType == StarShipType.SpyShip)
                            {
                                warshipwpn++;
                            }
                        }
                    }
                    if (warshipwpn >= 1)
                    {
                        tutstep = 8;
                        dproc = 0;
                    }
                }
                else if (tutstep == 8)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Now that you have a SpyShip, go see what the enemy is doing.");
                        DynamicEvents.CreateStarShip(58, 58, Game.Players[1], StarShipType.WarShip, 8, 8, false);
                        DynamicEvents.CreateStarShip(57, 58, Game.Players[1], StarShipType.WarShip, 8, 8, false);
                    }
                    else if (dproc == 5)
                    {
                        DisplayMessage("Move your SpyShip near the enemy StarSystem.");
                    }
                    else if (dproc >= 6)
                    {
                        warshipwpn = 0;
                        foreach (StarShip ship in Game.StarShips)
                        {
                            if (ship.Owner != Game.Players[0])
                            {
                                if (ship.ShipType == StarShipType.WarShip && ship.Value >= 7 && ship.VisibleTo[Game.Players[0]])
                                {
                                    warshipwpn++;
                                }
                            }
                        }
                        if (warshipwpn >= 1)
                        {
                            tutstep = 9;
                            dproc = 0;
                        }
                    }
                }
                else if (tutstep == 9)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Look out, the enemy has big WarShips!");
                    }
                    else if (dproc == 5)
                    {
                        DisplayMessage("Build some Drones or E-Mines to stop them!");
                    }
                    warshipwpn = 0;
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner != Game.Players[0])
                        {
                            if (ship.ShipType == StarShipType.WarShip && ship.Value >= 7)
                            {
                                warshipwpn++;
                            }
                        }
                    }
                    if (warshipwpn == 0)
                    {
                        tutstep = 10;
                        dproc = 0;
                    }
                }
                else if (tutstep == 10)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Good job, you have completed your defense training.");
                    }
                    else if (dproc == 5)
                    {
                        DisplayMessage("Now it's time to play a simple game of Solar Vengeance.");
                    }
                    else if (dproc == 10)
                    {
                        for (int d = 0; d < 8; d++)
                        {
                            int value = Random(1, 20);
                            if (value == 1)
                                value = Random(1, 20);
                            int shields = Random(0, value - 1);
                            int scanners = (int)(Random(0, value) * Random(0, 2));
                            if (scanners == 1)
                                scanners = 0;
                            double resources = Random(0, value) * Random(0, 3);
                            StarSystem system = DynamicEvents.CreateStarSystem(Random(30, 50), Random(30, 50), value, shields, scanners, resources);
                        }
                        for (int d = 0; d < 8; d++)
                        {
                            int value = Random(1, 20);
                            if (value == 1)
                                value = Random(1, 20);
                            int shields = Random(0, value - 1);
                            int scanners = (int)(Random(0, value) * Random(0, 2));
                            if (scanners == 1)
                                scanners = 0;
                            double resources = Random(0, value) * Random(0, 3);
                            StarSystem system = DynamicEvents.CreateStarSystem(Random(50, 70), Random(50, 70), value, shields, scanners, resources);
                        }
                    }
                    else if (dproc == 15)
                    {
                        DisplayMessage("When you have a cluster of low value StarSystems, you can use a Freighter.");
                    }
                    else if (dproc == 20)
                    {
                        DisplayMessage("A Freighter can transport Resources from StarSystem to StarSystem.");
                    }
                    else if (dproc == 25)
                    {
                        DisplayMessage("To order a Freighter, first click on it on the map.");
                    }
                    else if (dproc == 30)
                    {
                        DisplayMessage("Next, click on a friendly StarSystem you want to Transport Resources from.");
                    }
                    else if (dproc == 35)
                    {
                        DisplayMessage("Next, click on a friendly StarSystem you want to Transport the Resources to, followed by the \"Complete Order\" button.");
                    }
                }
            }
            else if (_TutorialLevel.Value == 3)
            {
                if (impulse == 1)
                {
                    tutstep = 0;
                    dproc = 0;
                    DisplayMessage("Welcome to the Tutorial Part 3.");
                }
                else if (impulse == 10)
                {
                    //Game.DS_CreateExplosion(50, 50, 400, Color.Yellow, Color.WhiteSmoke, 1, 3, 200);
                    DisplayMessage("Here you will learn about Wormholes, Black Holes, Nebula, and Pulsars.");
                }
                else if (impulse == 15)
                {
                    DisplayMessage("First thing you will learn is the Wormhole.");
                }
                else if (impulse == 20)
                {
                    DisplayMessage("Here is a Wormhole. A Wormhole transports a StarShip to an unknown location on the map.");
                    DynamicEvents.CreateWormhole(40, 35, 50, 45);
                }
                else if (impulse == 25)
                {
                    DisplayMessage("After you travel through a Wormhole, its end point is displayed as a line ");
                }
                else if (impulse == 30)
                {
                    DisplayMessage("on the mini-map.");
                }
                else if (impulse == 35)
                {
                    DisplayMessage("Now, build a StarShip to explore the Wormhole.");
                }
                if (tutstep == 0 && impulse >= 36)
                {
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            tutstep = 1;
                            dproc = 0;
                        }
                    }
                }
                else if (tutstep == 1)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("OK, now click on your StarShip.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Next, click on the Wormhole to move the StarShip to it.");
                    }
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.Order != null)
                                if (ship.Order.OrderType == OrderType.Move)
                                {
                                    tutstep = 2;
                                    dproc = 0;
                                }
                        }
                    }
                }
                else if (tutstep == 2)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("OK, now watch as your StarShip gets transported to an unknown location.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("You will hear a sound if your StarShip enters a Wormhole.");
                    }
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            if (ship.Order == null)
                            {
                                tutstep = 3;
                                dproc = 0;
                            }
                        }
                    }
                }
                else if (tutstep == 3)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Alright, now you know where that Wormhole leads to.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Now you will learn about the more sinister Black Holes.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("When a StarShip is near a Black Hole, it will get pulled toward the Black Hole.");
                    }
                    else if (dproc == 16)
                    {
                        DisplayMessage("Black Holes cannot be seen by Scanners. Black Holes can only be found if a StarShip gets pulled next to one.");
                    }
                    else if (dproc == 25)
                    {
                        DisplayMessage("When a StarShip enters a Black Hole, the StarShip is destroyed.");
                    }
                    else if (dproc == 30)
                    {
                        DisplayMessage("Watch what happens when a StarShip gets near a Black Hole.");
                        DynamicEvents.CreateBlackHole(50, 50, 10);
                    }
                    warshipwpn = 0;
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            warshipwpn++;
                        }
                    }
                    if (warshipwpn == 0)
                    {
                        tutstep = 4;
                        dproc = 0;
                    }
                }
                else if (tutstep == 4)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("See what Happened?");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("You usually want to steer well clear of Black Holes.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("If you try to move away from a Black Hole early enough, you can escape.");
                    }
                    else if (dproc == 16)
                    {
                        DisplayMessage("The third type of cosmic terrain you will learn about is the Pulsar.");
                    }
                    else if (dproc == 21)
                    {
                        DisplayMessage("Pulsars are high energy stars that emit a large amount of energy.");
                    }
                    else if (dproc == 26)
                    {
                        DisplayMessage("Any StarShip adjacent to a Pulsar will get repaired instantly.");
                    }
                    else if (dproc == 31)
                    {
                        DynamicEvents.CreatePulsar(40, 45);
                        DisplayMessage("Now build another StarShip from your Capital StarSystem.");
                    }
                    warshipwpn = 0;
                    foreach (StarShip ship in Game.StarShips)
                    {
                        if (ship.Owner == Game.Players[0])
                        {
                            warshipwpn++;
                        }
                    }
                    if (warshipwpn >= 1)
                    {
                        tutstep = 5;
                        dproc = 0;
                    }
                }
                else if (tutstep == 5)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Now, watch what happens to your StarShip when you move next to a Pulsar.");
                    }
                    else if (dproc == 6)
                    {
                        DynamicEvents.DamageStarShip(Game.StarShips[0], 4);
                        DynamicEvents.CreateExplosion(Game.StarShips[0].X, Game.StarShips[0].Y, 50, SCGColor.Yellow, SCGColor.Red, 1, 4, 30, true);
                        DisplayMessage("Move your StarShip next to the Pulsar.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("Hehe, you didn't expect that?");
                    }
                    else if (dproc == 16)
                    {
                        DisplayMessage("Just move your StarShip next to the Pulsar.");
                    }
                    else if (dproc >= 17)
                    {
                        warshipwpn = 0;
                        foreach (StarShip ship in Game.StarShips)
                        {
                            if (ship.Owner == Game.Players[0])
                            {
                                warshipwpn = ship.Health;
                            }
                        }
                        if (warshipwpn == 100)
                        {
                            tutstep = 6;
                            dproc = 0;
                        }
                    }
                }
                else if (tutstep == 6)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("See, good as new again!");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("Pulsars are valuable! Make sure your opponents don't get one.");
                    }
                    else if (dproc == 16)
                    {
                        DisplayMessage("Now for the last part of this Tutorial, Nebula.");
                    }
                    else if (dproc == 21)
                    {
                        DisplayMessage("Nebula can effectively turn off any Scanners that are within.");
                    }
                    else if (dproc == 26)
                    {
                        DisplayMessage("But Nebula can also hide your StarSystems and StarShips from your enemies.");
                    }
                    else if (dproc == 31)
                    {
                        DisplayMessage("This is what Nebula looks like.");
                        for (int x = 30; x <= 35; x++)
                            for (int y = 30; y <= 35; y++)
                                DynamicEvents.SetTerrain(x, y, 'N'); //'N'=visible nebula ' '=clear 'n'=invisible nebula
                        TmpStar = DynamicEvents.CreateStarSystem(35, 35, 20, 0, 50, 20);
                    }
                    else if (dproc == 36)
                    {
                        DisplayMessage("See how the StarSystem in the Nebula cannot be seen by you?");
                    }
                    else if (dproc == 41)
                    {
                        DisplayMessage("Now move your StarShip next to that StarSystem.");
                    }
                    else if (dproc >= 31)
                    {
                        warshipwpn = 0;
                        foreach (StarShip ship in Game.StarShips)
                        {
                            if (ship.Owner == Game.Players[0])
                            {
                                if (ship.Order != null)
                                    if (ship.Order.OrderType == OrderType.Move)
                                        warshipwpn = 1;
                            }
                        }
                        if (warshipwpn == 1)
                        {
                            tutstep = 7;
                            dproc = 0;
                        }
                    }
                }
                else if (tutstep == 7)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("OK, you are doing a good job with the orders.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Only when your StarShip is next to StarSystem in a Nebula can you then see what it is.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("If this StarSystem is a good one, you can conquer it.");
                    }
                    if (TmpStar.Owner == Game.Players[0])
                    {
                        tutstep = 8;
                        dproc = 0;
                    }
                }
                else if (tutstep == 8)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("See? Even though this StarSystem has enough scanners to see the other one over there,");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("... the Nebula blocks the Scanners of this StarSystem.");
                    }
                    else if (dproc == 11)
                    {
                        DisplayMessage("This same thing happens when a StarSystem is within certain background image.");
                    }
                    else if (dproc == 16)
                    {
                        DisplayMessage("Background images in some Scenarios are actual Nebula.");
                    }
                    else if (dproc == 21)
                    {
                        for (int wh = Game.Wormholes.Count - 1; wh >= 0; wh--)
                        {
                            DynamicEvents.RemoveObject(Game.Wormholes[wh]);
                        }
                        DynamicEvents.CreateWormhole(31, 31, 70, 70);
                        for (int d = 0; d < 8; d++)
                        {
                            int value = Random(1, 20);
                            if (value == 1)
                                value = Random(1, 20);
                            int shields = Random(0, value - 1);
                            int scanners = (int)(Random(0, value) * Random(0, 2));
                            if (scanners == 1)
                                scanners = 0;
                            double resources = Random(0, value) * Random(0, 3);
                            StarSystem system = DynamicEvents.CreateStarSystem(Random(50, 70), Random(50, 70), value, shields, scanners, resources);
                        }
                        DisplayMessage("Now there is a Wormhole somewhere in the Nebula. If you can find it.");
                    }
                    else if (dproc == 21)
                    {
                        DisplayMessage("Go through the Wormhole if you find it.");
                    }
                    if (Game.Wormholes[0].DiscoveredBy[Game.Players[0]] == true)
                    {
                        tutstep = 9;
                        dproc = 0;
                    }
                }
                else if (tutstep == 9)
                {
                    dproc++;
                    if (dproc == 1)
                    {
                        DisplayMessage("Very good! Now you are ready for the final test.");
                    }
                    else if (dproc == 6)
                    {
                        DisplayMessage("Take over the enemy Capital before playing the final part of this Tutorial.");
                    }
                }
            }
            else if (_TutorialLevel.Value == 4)
            {
                if (impulse == 1)
                {
                    wanderer = null;
                    tutstep = 0;
                    dproc = 0;
                    DynamicEvents.CreateExplosion(50, 50, 400, SCGColor.Yellow, SCGColor.White, 1, 3, 200, true);
                    DisplayMessage("Welcome to the Tutorial Part 4, your final test!");
                }
                else if (impulse == 10)
                {
                    DisplayMessage("You are now going to complete a real Scenario.");
                }
                else if (impulse == 15)
                {
                    DisplayMessage("Use all the knowledge that you learned in the first three parts!");
                }
                else if (impulse == 20)
                {
                    DisplayMessage("And compete in your first challenge!");
                }
                else if (impulse == 25)
                {
                    DisplayMessage("To win this challenge, you need to eliminate the enemy Capital.");
                }
                else if (impulse == 30)
                {
                    DisplayMessage("But you have to do it before the Black Hole consumes the enemy Capital, or your Capital!");
                }
                else if (impulse == 35)
                {
                    DisplayMessage("Get ready to go in 5 seconds ...");
                }
                else if (impulse == 40)
                {
                    DisplayMessage("Go!");
                    tutstep = 1;
                }

                if (tutstep == 1)
                {
                    if (wanderer != null)
                    {
                        dproc++;
                        if (dproc == 40)
                        {
                            dproc = 0;
                            DynamicEvents.SetBlackHoleRadius(wanderer, wanderer.Radius + 1);
                        }
                        for (int s = Game.StarSystems.Count - 1; s >= 0; s--)
                        {
                            StarSystem sys = Game.StarSystems[s];
                            if (StarX.ContainsKey(sys.Name) == false)
                            {
                                StarX.Add(sys.Name, sys.X);
                                StarY.Add(sys.Name, sys.Y);
                            }

                            double distfromblack = ArcDistance(sys.X, sys.Y, wanderer.X, wanderer.Y);
                            if (distfromblack <= wanderer.Radius)
                            {
                                if (Random(0, wanderer.Radius) >= distfromblack && Random(0, 2) == 2)
                                {
                                    double getdirdeg = FindDirectionDeg(StarX[sys.Name], StarY[sys.Name], wanderer.X, wanderer.Y);
                                    StarX[sys.Name] = StarX[sys.Name] + MoveObjectX(getdirdeg, 1);
                                    StarY[sys.Name] = StarY[sys.Name] + MoveObjectY(getdirdeg, 1);
                                    if (sys.X >= wanderer.X - 1 && sys.Y >= wanderer.Y - 1 && sys.X <= wanderer.X + 1 && sys.Y <= wanderer.Y + 1)
                                    {
                                        SVMapObject gobj = sys;
                                        if (sys.IsCapital == true)
                                        {
                                            Game.Players[0].Eliminated = true;
                                        }
                                        DynamicEvents.RemoveObject(gobj);  //need to fix error when trying to remove StarSysyem.
                                        DynamicEvents.CreateExplosion(50, 50, 400, SCGColor.Yellow, SCGColor.White, 1, 3, 200, true);
                                    }
                                    else
                                    {
                                        SVMapObject gobj = sys;
                                        DynamicEvents.RelocateObject(gobj, (int)StarX[sys.Name], (int)StarY[sys.Name]);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        wanderer = DynamicEvents.CreateBlackHole(50, 50, 2);
                    }
                }
            }
        }

        public override IList<StarShipType> AddedStarShipTypes
        {
            get
            {
                if (_TutorialLevel.Value <= 3)
                {
                    List<StarShipType> addstarships = new List<StarShipType>();
                    addstarships.Add(StarShipType.Drone);
                    addstarships.Add(StarShipType.WarShip);
                    addstarships.Add(StarShipType.EMine);
                    addstarships.Add(StarShipType.ScanShip);
                    addstarships.Add(StarShipType.SpyShip);
                    addstarships.Add(StarShipType.Freighter);
                    return addstarships;
                }
                else
                {
                    return base.AddedStarShipTypes;
                }
            }
        }
        
        public override void BuildScenario(int numPlayers, int capitalValues, int startingResources)
        {
            if (_TutorialLevel.Value <= 3)
            {
                MyCap = CreateStarSystem(40, 40, 20, 10, 100, 100);
                ECap = CreateStarSystem(60, 60, 20, 10, 100, 100);

                AssignCapital(Game.Players[0], new SCGRect(39, 39, 3, 3));
                AssignCapital(Game.Players[1], new SCGRect(39, 39, 3, 3));

                CreateWormhole(59, 59, 59, 59);
                CreateWormhole(59, 60, 59, 60);
                CreateWormhole(59, 61, 59, 61);
                CreateWormhole(60, 59, 60, 59);
                CreateWormhole(60, 61, 60, 61);
                CreateWormhole(61, 59, 61, 59);
                CreateWormhole(61, 60, 61, 60);
                CreateWormhole(61, 61, 61, 61);
            }
            else
            {
                CreateStarCluster(30, 50, 50, 50, 50, 35, 2);
                int numNebula = SVGame.RNG.Next(4) + 2;
                while (numNebula > 0)
                {
                    CreateNebula(SVGame.RNG.Next(40) + 30, SVGame.RNG.Next(40) + 30, SVGame.RNG.Next(5) + 4, SVGame.RNG.Next(40) + 30);
                    numNebula--;
                }
                int numWormholes = SVGame.RNG.Next(4) + 1;
                while (numWormholes > 0)
                {
                    CreateWormhole(SVGame.RNG.Next(100), SVGame.RNG.Next(100), SVGame.RNG.Next(40) + 30, SVGame.RNG.Next(40) + 30);
                    numWormholes--;
                }
                numWormholes = SVGame.RNG.Next(4) + 1;
                while (numWormholes > 0)
                {
                    CreateWormhole(SVGame.RNG.Next(40) + 30, SVGame.RNG.Next(40) + 30, SVGame.RNG.Next(100), SVGame.RNG.Next(100));
                    numWormholes--;
                }
                int numPulsars = SVGame.RNG.Next(2) + 1;
                while (numPulsars > 0)
                {
                    CreatePulsar(SVGame.RNG.Next(40) + 30, SVGame.RNG.Next(40) + 30);
                    numPulsars--;
                }
            }

            //Assign Beginner
            if (Game != null && Game.Players.Count > 1)
                Game.Players[1].DesiredBrainName = "Beginner";
        }

        //************************************* Custom Functions! *******************************************

        //find direction in degrres
        public double FindDirectionDeg(double basex, double basey, double targetx, double targety)
        {
            double bx = basex;
            double by = basey;
            double tx = targetx;
            double ty = targety;
            double radians = Math.PI / 180;
            double modt = 0;

            bx = tx - bx;
            by = ty - by;
            modt = Math.Sqrt((bx * bx) + (by * by));
            modt = by / modt;

            if (modt <= -1) modt = -0.99999999999999999999999999;
            if (modt >= 1) modt = 0.99999999999999999999999999;
            modt = Math.Asin(modt);

            if (bx > 0)
                modt = (modt / radians) + 90;
            else
                modt = 180 - (modt / radians) + 90;

            return modt;
        }

        //Rotate Direction
        public double RotateDirectionDeg(double direction, double increment)
        {
            double d = direction;
            double i = increment;
            d = d + i;

            while (d >= 360) d = d - 360;
            while (d < 0) d = d + 360;

            return d;
        }

        //Move to Direction
        public double MoveObjectX(double direction, double Increment)
        {
            double i = Increment;
            double d = direction;
            double radians = Math.PI / 180;

            d = Math.Sin(d * radians) * i;

            return d;
        }
        public double MoveObjectY(double direction, double Increment)
        {
            double i = Increment;
            double d = direction;
            double radians = Math.PI / 180;

            d = 0 - Math.Cos(d * radians) * i;

            return d;
        }

        //find pathagorean distance (radius)
        public double ArcDistance(int BaseX, int BaseY, int TargetX, int TargetY)
        {
            double a = 0;
            double b = 0;
            double c = 0;

            a = Math.Abs(BaseX - TargetX);
            b = Math.Abs(BaseY - TargetY);
            a = a * a;
            b = b * b;

            c = Math.Sqrt(a + b);

            return c;
        }

    }
}
